package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EDeviceOldDao;
import com.hongxun.modules.eys.entity.EDeviceOldEntity;
import com.hongxun.modules.eys.service.EDeviceOldService;


@Service("eDeviceOldService")
public class EDeviceOldServiceImpl implements EDeviceOldService {
    @Autowired
    private EDeviceOldDao eDeviceOldDao;

    @Override
    public EDeviceOldEntity queryObject(String guid) {
        return eDeviceOldDao.queryObject(guid);
    }

    @Override
    public List<EDeviceOldEntity> queryList(Map<String, Object> map) {
        return eDeviceOldDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return eDeviceOldDao.queryTotal(map);
    }

    @Override
    public void save(EDeviceOldEntity eDeviceOld) {
        if (eDeviceOld.getGuid() == null || eDeviceOld.getGuid().equals("")) {

            eDeviceOld.setGuid(UUID.randomUUID().toString());
        }
        eDeviceOldDao.save(eDeviceOld);
    }

    @Override
    public void update(EDeviceOldEntity eDeviceOld) {
        eDeviceOldDao.update(eDeviceOld);
    }

    @Override
    public void delete(String guid) {
        eDeviceOldDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        eDeviceOldDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<EDeviceOldEntity> entities) {
        for (EDeviceOldEntity d : entities) {
            if (d.getDRDatastate().equals("删除")) {
                eDeviceOldDao.delete(d.getGuid());
            } else {
                EDeviceOldEntity eCrossCostEntity = eDeviceOldDao.queryObject(d.getGuid());
                if (eCrossCostEntity == null) {
                    eDeviceOldDao.save(d);
                } else {
                    eDeviceOldDao.update(d);
                }
            }
        }
    }

}
